﻿#pragma once

#include <E_Transfer.nanopb.h>

#include "proto_common_equip.pb.h"
#include "NFServerComm/NFServerCommon/NFIDescStoreEx.h"
#include "NFServerComm/NFServerCommon/NFIDescTemplate.h"
#include "NFComm/NFObjCommon/NFResDb.h"
#include "NFComm/NFObjCommon/NFShmMgr.h"
#include "NFComm/NFShmStl/NFShmHashMap.h"
#include "NFComm/NFShmStl/NFShmVector.h"
#include "NFLogicCommon/NFDescStoreTypeDefines.h"

struct E_TransferTree;
const int MAX_TRANSFER_ID_NUM = 50;
const int MAX_TRANFER_LAYER = 50;
const int MAX_TREE_NODE_PER_LAYER = 5;
const int MAX_AUTO_GET_NODE_NUM = 30;

struct TTransferLayerInfo
{
    TTransferLayerInfo()
    {
        if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
        {
            CreateInit();
        }
        else
        {
            ResumeInit();
        }
    }

    int CreateInit()
    {
        m_iTransferID = INVALID_ID;
        m_iMaxLayer = 0;
        memset(&m_aiNodeID, 0, sizeof(m_aiNodeID));
        return 0;
    }

    int ResumeInit()
    {
        return 0;
    }

    int m_iTransferID;
    int m_aiNodeID[MAX_TRANFER_LAYER][MAX_TREE_NODE_PER_LAYER];
    int m_iMaxLayer;
    NFShmVector<int, MAX_AUTO_GET_NODE_NUM> m_aiAutoNodeID;
};

const int MAX_TRANSFER_DESC_NUM = 20;
const int MAX_TRANSFER_ID_VALUE = 1000;
const int MAX_TRANSFER_NUM = 50;

struct TTransferFashion
{
    int m_iTransferID;
    int m_aiFashionID[proto_ff::enFashionType_MAX];
};

class TransferDescEx : public NF_OBJECT_GLOBAL_TEMPLATE_MACRO(TransferDescEx, EOT_CONST_TRANSFER_DESC_EX_ID, NFIDescStoreEx)
public:
    TransferDescEx();

    virtual ~TransferDescEx();

    int CreateInit();

    int ResumeInit();

public:
    virtual int Load() override;

    virtual int CheckWhenAllDataLoaded() override;

public:
    int AddTransferFashion(int iTransferID, const std::vector<int>& vecFashionIds);

public:
    const TTransferLayerInfo* GetTransferLayerInfo(int iTransferID) const;
    const E_TransferTree* GetDescByPos(int iTransferID, int iLayer, int iPos);

public:
    E_Transfer* GetDescByProf(int iProf) const;
    int GetTransferFashion(int iTransferID, int iIndex) const;
    const TTransferFashion* GetTransferFashion(int iTransferID) const;
    bool IsProfAndTransferMatch(int iProf, int iTranferID) const;

private:
    TTransferLayerInfo* FindTransferLayerInfo(int iTransferID);

    TTransferLayerInfo* CreateTransferLayerInfo(int iTransferID);

    int AddLayerInfo(TTransferLayerInfo* pLayerInfo, E_TransferTree* pstDesc);

private:
    bool IS_VALID_TRANSFER_LAYER_POS(int iPos) const { return iPos > 0 && iPos < MAX_TREE_NODE_PER_LAYER; }
    bool IS_VALID_TRANSFER_LAYER(int iLayer) const { return iLayer >= 0 && iLayer < MAX_TRANFER_LAYER; }

private:
    NFShmHashMap<int, TTransferLayerInfo, MAX_TRANSFER_ID_NUM> m_astTransferLayerInfo;
    NFShmHashMap<int, TTransferFashion, MAX_TRANSFER_NUM> m_astFashion;
};
